package com.lzy.fabric.entity.creatures.misc.skeleton;

import com.lzy.fabric.enchantments.ModEnchantmentInit;
import com.lzy.fabric.events.ModCiteThunder;
import com.lzy.fabric.item.ModItems;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityIronGolem;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySlime;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.Calendar;

/**
 * @author 骷髅战士
 */
public class SkeletonWarrior extends EntitySkeleton {

    public SkeletonWarrior(World worldIn) {
        super(worldIn);
    }

    /**
     * 微调AI
     */
    @Override
    protected void initEntityAI() {
        super.initEntityAI();
        //攻击村民
        this.targetTasks.addTask(4, new EntityAINearestAttackableTarget(this, EntityVillager.class, true));
        this.tasks.addTask(4, new EntityAIAvoidEntity(this, EntitySlime.class,16.0F,1.0D,2D));
    }

    /**
     * 修改视野，移速，攻击力，盔甲值属性，生命上限数值
     */
    @Override
    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(16.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.23000000417232513D);
        this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(10.0D);
        this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0D);
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(24);
    }
    /**
     *设置持有物品
     */
    @Override
    @Nullable
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
    {
        livingdata = super.onInitialSpawn(difficulty, livingdata);
        this.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, new ItemStack(ModItems.MASSAGE));
        this.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, new ItemStack(ModItems.SUPERIOR_WOOD_ROOT));
        /**
         * 头盔
         */
        this.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Blocks.MOB_SPAWNER));
        /**
         * 胸甲
         */
        this.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.DIAMOND_CHESTPLATE));
        /**
         * 护腿
         */
        this.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.DIAMOND_LEGGINGS));
        /**
         * 鞋子
         */
        this.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.DIAMOND_BOOTS));

        this.setCanPickUpLoot(true);


        return livingdata;
    }

    /**
     * 掉落物品
     */
    @Override
    protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, DamageSource source) {
        if (!world.isRemote){
            //如果玩家有抢夺
            if (lootingModifier>0){
                if (rand.nextFloat()<0.7f){
                    dropItem(ModItems.RUBINE,6);
                    dropItem(ModItems.SUPERIOR_WOOD_ROOT,6);
                }else
                if (rand.nextFloat()<0.3f){
                    dropItem(ModItems.MASSAGE,1);
                }
            }else {
                dropItem(ModItems.SUPERIOR_WOOD_ROOT,16);
            }

        }
    }
}
